# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# External users should depend only on ":math_opt" and include
# "math_opt.h". Hence other libraries are private.
package(default_visibility = [
    "//ortools/math_opt/constraints:__subpackages__",
])

cc_library(
    name = "math_opt",
    hdrs = ["math_opt.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":model",
        ":solve",
        ":solver_resources",
    ],
)

cc_library(
    name = "basis_status",
    srcs = ["basis_status.cc"],
    hdrs = ["basis_status.h"],
    deps = [
        ":enums",
        "//ortools/math_opt:solution_cc_proto",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "sparse_containers",
    srcs = ["sparse_containers.cc"],
    hdrs = ["sparse_containers.h"],
    deps = [
        ":basis_status",
        ":linear_constraint",
        ":objective",
        ":variable_and_expressions",
        "//ortools/base:logging",
        "//ortools/base:status_macros",
        "//ortools/math_opt:solution_cc_proto",
        "//ortools/math_opt:sparse_containers_cc_proto",
        "//ortools/math_opt/constraints/quadratic:quadratic_constraint",
        "//ortools/math_opt/core:sparse_vector_view",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/math_opt/storage:model_storage_types",
        "//ortools/math_opt/validators:sparse_vector_validator",
        "@abseil-cpp//absl/algorithm:container",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/types:span",
        "@protobuf",
    ],
)

cc_library(
    name = "model",
    srcs = ["model.cc"],
    hdrs = ["model.h"],
    deps = [
        ":key_types",
        ":linear_constraint",
        ":objective",
        ":update_tracker",
        ":variable_and_expressions",
        "//ortools/base:intops",
        "//ortools/base:status_macros",
        "//ortools/math_opt:model_cc_proto",
        "//ortools/math_opt:model_update_cc_proto",
        "//ortools/math_opt/constraints/indicator:indicator_constraint",
        "//ortools/math_opt/constraints/quadratic:quadratic_constraint",
        "//ortools/math_opt/constraints/second_order_cone:second_order_cone_constraint",
        "//ortools/math_opt/constraints/second_order_cone:storage",
        "//ortools/math_opt/constraints/sos:sos1_constraint",
        "//ortools/math_opt/constraints/sos:sos2_constraint",
        "//ortools/math_opt/constraints/util:model_util",
        "//ortools/math_opt/storage:linear_expression_data",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/math_opt/storage:model_storage_types",
        "//ortools/math_opt/storage:sparse_coefficient_map",
        "//ortools/math_opt/storage:sparse_matrix",
        "//ortools/util:fp_roundtrip_conv",
        "@abseil-cpp//absl/base:nullability",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/log:die_if_null",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "variable_and_expressions",
    srcs = ["variable_and_expressions.cc"],
    hdrs = ["variable_and_expressions.h"],
    deps = [
        ":formatters",
        ":key_types",
        "//ortools/base",
        "//ortools/base:intops",
        "//ortools/base:map_util",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/math_opt/storage:model_storage_item",
        "//ortools/math_opt/storage:model_storage_types",
        "//ortools/util:fp_roundtrip_conv",
        "@abseil-cpp//absl/base:core_headers",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/strings",
    ],
)

cc_library(
    name = "objective",
    srcs = ["objective.cc"],
    hdrs = ["objective.h"],
    deps = [
        ":key_types",
        ":variable_and_expressions",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/math_opt/storage:model_storage_item",
        "//ortools/math_opt/storage:model_storage_types",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/strings",
    ],
)

cc_library(
    name = "linear_constraint",
    hdrs = ["linear_constraint.h"],
    deps = [
        ":key_types",
        ":variable_and_expressions",
        "//ortools/math_opt/constraints/util:model_util",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/math_opt/storage:model_storage_item",
        "//ortools/math_opt/storage:model_storage_types",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/strings",
    ],
)

cc_library(
    name = "solution",
    srcs = ["solution.cc"],
    hdrs = ["solution.h"],
    deps = [
        ":basis_status",
        ":enums",
        ":linear_constraint",
        ":objective",
        ":sparse_containers",
        ":variable_and_expressions",
        "//ortools/base:status_macros",
        "//ortools/math_opt:result_cc_proto",
        "//ortools/math_opt:solution_cc_proto",
        "//ortools/math_opt:sparse_containers_cc_proto",
        "//ortools/math_opt/constraints/quadratic:quadratic_constraint",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/util:status_macros",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "solve_result",
    srcs = ["solve_result.cc"],
    hdrs = ["solve_result.h"],
    deps = [
        ":enums",
        ":linear_constraint",
        ":solution",
        ":variable_and_expressions",
        "//ortools/base:protoutil",
        "//ortools/base:status_macros",
        "//ortools/gscip:gscip_cc_proto",
        "//ortools/math_opt:result_cc_proto",
        "//ortools/math_opt:solution_cc_proto",
        "//ortools/math_opt/core:math_opt_proto_utils",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/port:proto_utils",
        "//ortools/util:fp_roundtrip_conv",
        "//ortools/util:status_macros",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/time",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "map_filter",
    srcs = ["map_filter.cc"],
    hdrs = ["map_filter.h"],
    deps = [
        ":key_types",
        ":linear_constraint",
        ":model",
        ":variable_and_expressions",
        "//ortools/base:status_macros",
        "//ortools/math_opt:sparse_containers_cc_proto",
        "//ortools/math_opt/storage:model_storage",
        "@abseil-cpp//absl/algorithm:container",
        "@abseil-cpp//absl/container:flat_hash_set",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
    ],
)

cc_library(
    name = "callback",
    srcs = ["callback.cc"],
    hdrs = ["callback.h"],
    deps = [
        ":enums",
        ":map_filter",
        ":sparse_containers",
        ":variable_and_expressions",
        "//ortools/base",
        "//ortools/base:intops",
        "//ortools/base:protoutil",
        "//ortools/base:status_macros",
        "//ortools/math_opt:callback_cc_proto",
        "//ortools/math_opt:sparse_containers_cc_proto",
        "//ortools/math_opt/core:sparse_vector_view",
        "//ortools/math_opt/storage:model_storage",
        "@abseil-cpp//absl/container:flat_hash_set",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/time",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "key_types",
    hdrs = ["key_types.h"],
    deps = [
        "//ortools/math_opt/storage:model_storage",
        "//ortools/math_opt/storage:model_storage_item",
        "@abseil-cpp//absl/algorithm:container",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "model_solve_parameters",
    srcs = ["model_solve_parameters.cc"],
    hdrs = ["model_solve_parameters.h"],
    deps = [
        ":linear_constraint",
        ":map_filter",
        ":model",
        ":solution",
        ":sparse_containers",
        ":variable_and_expressions",
        "//ortools/base:protoutil",
        "//ortools/base:status_macros",
        "//ortools/math_opt:model_parameters_cc_proto",
        "//ortools/math_opt:solution_cc_proto",
        "//ortools/math_opt:sparse_containers_cc_proto",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/util:status_macros",
        "@abseil-cpp//absl/algorithm:container",
        "@abseil-cpp//absl/container:flat_hash_set",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/time",
        "@protobuf",
    ],
)

cc_library(
    name = "update_tracker",
    srcs = ["update_tracker.cc"],
    hdrs = ["update_tracker.h"],
    deps = [
        "//ortools/base:logging",
        "//ortools/math_opt:model_cc_proto",
        "//ortools/math_opt:model_update_cc_proto",
        "//ortools/math_opt/storage:model_storage",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
    ],
)

cc_library(
    name = "message_callback",
    srcs = ["message_callback.cc"],
    hdrs = ["message_callback.h"],
    deps = [
        "//ortools/base:logging",
        "//ortools/base:source_location",
        "@abseil-cpp//absl/base:core_headers",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/synchronization",
        "@abseil-cpp//absl/types:span",
        "@protobuf",
    ],
)

cc_library(
    name = "solver_init_arguments",
    hdrs = ["solver_init_arguments.h"],
    deps = [
        ":streamable_solver_init_arguments",
        "//ortools/math_opt/core:non_streamable_solver_init_arguments",
    ],
)

cc_library(
    name = "solve_arguments",
    srcs = ["solve_arguments.cc"],
    hdrs = ["solve_arguments.h"],
    deps = [
        ":callback",
        ":message_callback",
        ":model_solve_parameters",
        ":parameters",
        "//ortools/base:status_macros",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/util:solve_interrupter",
        "@abseil-cpp//absl/container:flat_hash_set",
        "@abseil-cpp//absl/status",
    ],
)

cc_library(
    name = "solve",
    srcs = ["solve.cc"],
    hdrs = ["solve.h"],
    deps = [
        ":compute_infeasible_subsystem_arguments",
        ":compute_infeasible_subsystem_result",
        ":incremental_solver",
        ":model",
        ":parameters",
        ":solve_arguments",
        ":solve_impl",
        ":solve_result",
        ":solver_init_arguments",
        ":streamable_solver_init_arguments",
        ":update_result",
        "//ortools/math_opt:callback_cc_proto",
        "//ortools/math_opt:infeasible_subsystem_cc_proto",
        "//ortools/math_opt:parameters_cc_proto",
        "//ortools/math_opt/core:base_solver",
        "//ortools/math_opt/core:solver",
        "@abseil-cpp//absl/status:statusor",
    ],
)

cc_library(
    name = "streamable_solver_init_arguments",
    srcs = ["streamable_solver_init_arguments.cc"],
    hdrs = ["streamable_solver_init_arguments.h"],
    deps = [
        "//ortools/math_opt:parameters_cc_proto",
        "//ortools/math_opt/solvers:gurobi_cc_proto",
        "@abseil-cpp//absl/status:statusor",
    ],
)

cc_library(
    name = "parameters",
    srcs = ["parameters.cc"],
    hdrs = ["parameters.h"],
    deps = [
        ":enums",
        "//ortools/base:linked_hash_map",
        "//ortools/base:protoutil",
        "//ortools/base:status_macros",
        "//ortools/glop:parameters_cc_proto",
        "//ortools/gscip:gscip_cc_proto",
        "//ortools/math_opt:parameters_cc_proto",
        "//ortools/math_opt/solvers:glpk_cc_proto",
        "//ortools/math_opt/solvers:gurobi_cc_proto",
        "//ortools/math_opt/solvers:highs_cc_proto",
        "//ortools/port:proto_utils",
        "//ortools/sat:sat_parameters_cc_proto",
        "//ortools/util:status_macros",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/time",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "matchers",
    testonly = 1,
    srcs = ["matchers.cc"],
    hdrs = ["matchers.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":linear_constraint",
        ":math_opt",
        ":update_result",
        ":variable_and_expressions",
        "//ortools/base:gmock",
        "//ortools/base:logging",
        "//ortools/math_opt/constraints/quadratic:quadratic_constraint",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "enums",
    hdrs = ["enums.h"],
    deps = [
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/types:span",
    ],
)

cc_library(
    name = "statistics",
    srcs = ["statistics.cc"],
    hdrs = ["statistics.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":model",
        "//ortools/math_opt/storage:model_storage",
    ],
)

cc_library(
    name = "formatters",
    hdrs = ["formatters.h"],
    deps = ["//ortools/util:fp_roundtrip_conv"],
)

cc_library(
    name = "update_result",
    hdrs = ["update_result.h"],
    deps = ["//ortools/math_opt:model_update_cc_proto"],
)

cc_library(
    name = "compute_infeasible_subsystem_result",
    srcs = ["compute_infeasible_subsystem_result.cc"],
    hdrs = ["compute_infeasible_subsystem_result.h"],
    deps = [
        ":enums",
        ":key_types",
        ":linear_constraint",
        ":solve_result",
        ":variable_and_expressions",
        "//ortools/base:status_macros",
        "//ortools/math_opt:infeasible_subsystem_cc_proto",
        "//ortools/math_opt:result_cc_proto",
        "//ortools/math_opt/constraints/indicator:indicator_constraint",
        "//ortools/math_opt/constraints/quadratic:quadratic_constraint",
        "//ortools/math_opt/constraints/second_order_cone:second_order_cone_constraint",
        "//ortools/math_opt/constraints/sos:sos1_constraint",
        "//ortools/math_opt/constraints/sos:sos2_constraint",
        "//ortools/math_opt/core:math_opt_proto_utils",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/math_opt/validators:infeasible_subsystem_validator",
        "//ortools/util:status_macros",
        "@abseil-cpp//absl/algorithm:container",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/container:flat_hash_set",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
    ],
)

cc_library(
    name = "compute_infeasible_subsystem_arguments",
    hdrs = ["compute_infeasible_subsystem_arguments.h"],
    deps = [
        ":message_callback",
        ":parameters",
        "//ortools/util:solve_interrupter",
    ],
)

cc_library(
    name = "solver_resources",
    srcs = ["solver_resources.cc"],
    hdrs = ["solver_resources.h"],
    deps = [
        "//ortools/math_opt:rpc_cc_proto",
        "//ortools/port:proto_utils",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:string_view",
    ],
)

cc_library(
    name = "solve_impl",
    srcs = ["solve_impl.cc"],
    hdrs = ["solve_impl.h"],
    deps = [
        ":compute_infeasible_subsystem_arguments",
        ":compute_infeasible_subsystem_result",
        ":incremental_solver",
        ":model",
        ":parameters",
        ":solve_arguments",
        ":solve_result",
        ":update_result",
        ":update_tracker",
        "//ortools/base:status_macros",
        "//ortools/math_opt/core:base_solver",
        "//ortools/math_opt/storage:model_storage",
        "//ortools/util:solve_interrupter",
        "//ortools/util:status_macros",
        "@abseil-cpp//absl/functional:any_invocable",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/memory",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/synchronization",
    ],
)

cc_library(
    name = "incremental_solver",
    hdrs = ["incremental_solver.h"],
    deps = [
        ":compute_infeasible_subsystem_arguments",
        ":compute_infeasible_subsystem_result",
        ":parameters",
        ":solve_arguments",
        ":solve_result",
        ":update_result",
        "@abseil-cpp//absl/status:statusor",
    ],
)
